package com.jn.algorithm.day024.question78;

import java.util.*;

/**
 * @author 江南大学1033190417
 * @date 2022/5/15 10:05
 */
public class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        Deque<Integer> path = new ArrayDeque<>();
        dfs(res,path,0,nums);
        return res;
    }

    public void dfs(List<List<Integer>> res, Deque<Integer> path, int cur, int[] nums) {
        if (cur == nums.length) {
            res.add(new ArrayList<>(path));
            return;
        }
        //选择当前
        path.addLast(nums[cur]);
        dfs(res, path, cur + 1, nums);
        path.pollLast();
        //不选择当前
        dfs(res, path, cur + 1, nums);

    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3, 4};
        Solution solution=new Solution();
        System.out.println(solution.subsets(nums));

    }
}
